//index.js
//获取应用实例
const app = getApp()
const http = require("../../utils/http.js")

Page({
  data: {
    ScreenHeight: app.globalData.ScreenHeight,
    WindowHeight: app.globalData.WindowHeight,

    flag: true,

    PageCur: 'recommend',
    userInfo: {},
    hasUserInfo: false,

    version: '1.0.0'
  },
  NavChange(e) {
    if (e.currentTarget.dataset.cur == 'new') {
      if (!app.globalData.userInfo){
        wx.showToast({
          title: '请先登录账号哟',
          icon: 'none',
          duration: 2000
        })
        return;
      }
      this.setData({
        flag: false
      })
      setTimeout(function () {
        app.slideupshow(this, 'slide_up1', -(this.data.WindowHeight / 2), 1)
        setTimeout(function () {
          app.slideupshow(this, 'slide_up2', -(this.data.WindowHeight / 2), 1)
        }.bind(this), 100);
      }.bind(this), 50);
      return;
    }
    this.setData({
      PageCur: e.currentTarget.dataset.cur
    })
  },
  close: function() {
    //延时展现容器2，做到瀑布流的效果
    setTimeout(function () {
      app.slideupshow(this, 'slide_up2', this.data.WindowHeight / 2, 0)
      setTimeout(function () {
        app.slideupshow(this, 'slide_up1', this.data.WindowHeight / 2, 0)
        setTimeout(() => {
          this.setData({
            flag: true
          })
        }, 800)
      }.bind(this), 100);
    }.bind(this), 50);
  },
  make: function(e){
    let page = e.currentTarget.dataset.pagename
    wx.navigateTo({
      url: '/pages/'+page+'/'+page,
    })
  },
  onLoad: function (options) {
    http.get("/get")
      .then(res => {
        this.setData({
          version: res.data
        })
      })

    this.setData({
      flag: true
    })
    if (options.PageCur){
        this.setData({
          PageCur: options.PageCur
        })
    }
  },
  onReady: function(e) {
    // 使用 wx.createAudioContext 获取 audio 上下文 context

  }
})